package cn.edu.neusoft.yuejian4.yuejian_4.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.adapter.ClubListAdapter;
import cn.edu.neusoft.yuejian4.yuejian_4.adapter.TrainListAdapter;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Club;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.List_TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.model.ClubModel;
import cn.edu.neusoft.yuejian4.yuejian_4.model.TrainModel;

/**
 * Created by Lix on 2018/10/9.
 */

public class ClubFragment extends Fragment implements View.OnClickListener {

    private View view;
    private Button lv1,lv2,lv3;
    private RecyclerView recyclerView;
    private TextView title;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_club,container,false);
        initViews();
        initEvent();
        ClubModel clubModel = new ClubModel();
        clubModel.allClub(allclub);
        title.setText("俱乐部");
        return view;

    }

  List_TListener<Club> allclub = new List_TListener<Club>() {
      @Override
      public void onResponse(List<Club> list) {
          ClubListAdapter clubListAdapter = new ClubListAdapter(getContext(),list);
          recyclerView.setAdapter(clubListAdapter);
      }

      @Override
      public void onFail(String msg) {

      }
  };
    List_TListener<Club> hotclub = new List_TListener<Club>() {
        @Override
        public void onResponse(List<Club> list) {
            ClubListAdapter clubListAdapter = new ClubListAdapter(getContext(),list);
            recyclerView.setAdapter(clubListAdapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };

    List_TListener<Club> juliClub = new List_TListener<Club>() {
        @Override
        public void onResponse(List<Club> list) {
            ClubListAdapter clubListAdapter = new ClubListAdapter(getContext(),list);
            recyclerView.setAdapter(clubListAdapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void initEvent() {
        lv1.setOnClickListener(this);
        lv2.setOnClickListener(this);
        lv3.setOnClickListener(this);

    }

    private void initViews() {
        recyclerView = (RecyclerView)view.findViewById(R.id.rv_club);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        lv1 = (Button) view.findViewById(R.id.club_nor);
        lv2 = (Button) view.findViewById(R.id.club_renqi);
        lv3 = (Button)view.findViewById(R.id.club_rec);
        title = (TextView)view.findViewById(R.id.club_title);

    }



    @Override
    public void onClick(View v) {
        ClubModel clubModel = new ClubModel();
        switch (v.getId()){
            case R.id.club_nor:
                clubModel.allClub(allclub);
                title.setText("俱乐部");
                break;
            case R.id.club_renqi:
                clubModel.hotClub(hotclub);
                title.setText("俱乐部-人气排行");
                break;
            case R.id.club_rec:
                clubModel.distanceClub(juliClub);
                title.setText("俱乐部-距离排行");
                break;

        }
    }
}
